package com.codeerror.demo.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.codeerror.demo.R;

/**
 * 粉色的Toast
 */
public class PinkToast extends Toast {
    private static PinkToast instance;
    private PinkToast(Context context) {
        super(context);
    }

    public static PinkToast getInstance(Context context) {
        if (null == instance){
            synchronized (PinkToast.class){
                if (null == instance){
                    instance = new PinkToast(context);
                }
            }
        }
        return instance;
    }

    public static class Builder{
        private PinkToast toast;
        private View layout;
        private ImageView iv;
        private TextView tv;

        public Builder(Context context) {
            toast = getInstance(context);
            layout = LayoutInflater.from(context)
                    .inflate(R.layout.layout_dialog_toast, null, false);
            iv = layout.findViewById(R.id.iv_pink_toast);
            tv = layout.findViewById(R.id.tv_pink_toast);
        }

        public Builder setText(String s){
            tv.setText(s);
            return this;
        }

        public void showToast(){
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setView(layout);
            toast.show();
        }
    }
}
